package week4;
import java.util.*;

public class Day3 {
    //1.
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int[] arr = new int[n];
            for(int i=1;i<=n;i++) {
                arr[i-1]=i;
            }
            //交换
            int k = 2;
            while(k<n) {
                swap(arr,k-1,k);
                k+=2;
            }
            for(int i=0;i<n;i++) {
                System.out.print(arr[i]+" ");
            }
        }
    }
    public static void swap(int[] arr,int i,int j) {
        int tmp = arr[i];
        arr[i]=arr[j];
        arr[j]=tmp;
    }
    //2.
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            //1.输入
            int n = in.nextInt();
            int m = in.nextInt();
            int[] arr1 = new int[n];
            int[] arr2 = new int[m];
            for(int i=0;i<n;i++) arr1[i]=in.nextInt();
            for(int i=0;i<m;i++) arr2[i]=in.nextInt();
            Arrays.sort(arr1);
            Arrays.sort(arr2);
            //2.
            int[] ret = new int[m+n];
            int k=0,i=0,j=0;
            while(i<n&&j<m) {
                if(arr1[i]<arr2[j]) ret[k++]=arr1[i++];
                else if(arr1[i]>arr2[j]) ret[k++]=arr2[j++];
                else {
                    ret[k++]=arr1[i++];
                    j++;
                }
            }
            while(i<n) {
                ret[k++]=arr1[i++];
            }
            while(j<m) {
                ret[k++]=arr2[j++];
            }
            i=0;
            for(;i<k;i++) {
                System.out.print(ret[i]+" ");
            }
        }
    }
    //3.
    static int len;//保存最后结果

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String s = in.nextLine();
            dfs(s,0,s.length()-1,0);
            System.out.println(len);

        }
    }
    public static void dfs(String s,int left,int right,int ret) {
        if(left >= right) {

        }
        char c1 = s.charAt(left);
        char c2 = s.charAt(right);
        if(c1==c2) {
            dfs(s,left+1,right-1,ret+2);
        }else {
            int i=left+1;//找right
            int j=right-1;
            while(i<=right) {
                if(s.charAt(i++)==c2) break;
            }
            while(j>=left) {
                if(s.charAt(j--)==c2) break;
            }
            if(i<right) dfs(s,left+1,i-1,ret+2);
            if(j>left) dfs(s,j+1,right-1,ret+2);
        }
    }



}
